package com.ba.controller;

import com.ba.pojo.Card;
import com.ba.pojo.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/*
游玩的逻辑
 */
public class Play {
    List<Card> box=new ArrayList<>(54);
    public void start(){
        //1.准备牌
        //2.发牌
        //3.呈现每个玩家的牌
        //4.排列每个人手中的牌
        prepare();
        publish();
        show();


       for(Card card:box) {
           System.out.println(card);
       }

    }
    private void show(){
        p1.showCards();
        p2.showCards();
        p3.showCards();
    }
    private  Player p1,p2,p3;
    private void publish(){
        p1=new Player("John");
        p2=new Player("Jane");
        p3=new Player("Bob");

        for(int i=0;i<54;i++){
            int pos =new Random().nextInt(box.size());
            Card get=box.remove(pos);//拿到并且删除一张牌
            int which =i%3;//求得哪个玩家要收取这张牌
            switch(which){
                case 0:
                    p1.receiveCard(get);
                    break;
                case 1:
                    p2.receiveCard(get);
                    break;
                default:
                    p3.receiveCard(get);
            }


        }

    }


    private void prepare(){
        for(int i=1; i<14; i++){
            String str_num=String.valueOf(i);
            int t_num=i;

            switch(i){
                case 1:
                    str_num="A";
                    t_num=14;
                    break;
                case 2:
                    t_num=15;
                    break;
                case 11:
                    str_num="J";
                    break;
                case 12:
                    str_num="Q";
                    break;
                case 13:
                    str_num="K";
                    break;
            }


            Card c1=create("♠",str_num,t_num);
            Card c2=create("❤",str_num,t_num);
            Card c3=create("♦",str_num,t_num);
            Card c4=create("♣",str_num,t_num);

            box.add(c1);
            box.add(c2);
            box.add(c3);
            box.add(c4);


        }

        box.add(create("joke","",88));
        box.add(create("JOKE","",888));
    }

    private Card create(String pattern,String str_num,int t_size){
        Card c=new Card();
        c.setPattern(pattern);
        c.setStr_num(str_num);
        c.setT_size(t_size);
        return c;
    }



}
